<?php 
$filter1 = (isset($_POST['filter1']))?$_POST['filter1']:0;
//$filter2 = (isset($_POST['filter2']))?$_POST['filter2']:0;
//$filter3 = (isset($_POST['filter3']))?$_POST['filter3']:0;

if(isset($_POST['filter1']))
{
	$sql = "SELECT sum(se.total_score) AS total_score,sum(se.full_score) AS full_score
			FROM student_excercise AS se 
			JOIN student AS s ON s.id_student = se.id_student
			WHERE student_code=".$stucode;
	$result = mysql_query($sql, $link);
	mysql_query("SET NAMES UTF8");
	$numrows = mysql_num_rows($result);
	if($numrows > 0)
	{
		while ($arr = mysql_fetch_array($result))
		{

		}
	}
}

?>
<div class="well bs-component">
              <form class="form-horizontal" id="chartForm" method="post">
                <fieldset>
				<legend>ระบุข้อมูล</legend>
                  <div class="form-group">
                    <label class="col-lg-2 control-label">&nbsp;</label>
                    <div class="col-lg-10">
                      <div class="radio">
                        <label><input type="radio" name="filter1" id="filter1" value="1"<?php if ($filter1 == 1){ ?> checked <?php } ?>>เพศ</label>
                      </div>
                      <div class="radio">
                        <label><input type="radio" name="filter1" id="filter1" value="2"<?php if ($filter1 == 2){ ?> checked <?php } ?>>อายุ</label><br>
                      </div>
                      <div class="radio">
                        <label><input type="radio" name="filter1" id="filter1" value="3"<?php if ($filter1 == 3){ ?> checked <?php } ?>>อาชีพ</label><br>
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="col-lg-10 col-lg-offset-2">
						<button type="submit" class="btn btn-primary">ค้นหา</button>
						<button class="btn btn-default">ยกเลิก</button>
                    </div>
                  </div>
                </fieldset>
				
				<fieldset>
				<legend>แสดงกราฟ</legend>
				<div id="pie1" style="margin-top:20px; margin-left:20px; height:400px;"></div>
				</fieldset>
				
              </form>
            </div>
<script type="text/javascript">
 $(document).ready(function(){
	  var data = [
	    ['Heavy Industry20', 20],['Retail9', 9], ['Light Industry11', 11],
	    ['Out of home18', 18],['Commuting20', 20], ['Orientation22', 22]
	  ];
	  var plot1 = jQuery.jqplot ('pie1', [data],
	    {
		  gridPadding: {top:0, bottom:0, left:0, right:0},
	      seriesDefaults: {
	        // Make this a pie chart.
	        renderer: jQuery.jqplot.PieRenderer,
	        rendererOptions: {
	          // Put data labels on the pie slices.
	          // By default, labels show the percentage of the slice.
	          showDataLabels: true
	        }
	      },
	      legend: { show:true,location:'ne' }
	    }
	  );


	  $("#chartForm").validate({
		 
	       submitHandler: function(form) {
	    	   $.ajax({
	 	          type: "POST",
	 	          url: "chart_ajax.php",
	 	          data: $('#chartForm').serialize(),
	 	       success: function(result)
	 	       {
	 	    	  $("#divChart").html(data);
	 	       }
	 	     });
	       }
		})
	  
	});
</script>